package com.sg.service.biz.bff.nb;

import cn.hutool.core.bean.BeanUtil;
import com.alibaba.fastjson.JSONObject;
import com.sg.common.util.RedisUtil;
import com.sg.dto.integration.framework.OrgInductionRecordDto;
import com.wicket.okrcomponent.common.annotations.BanAuto;
import com.wicket.okrframework.common.redis.UserIndInfoForRedis;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.stream.Collectors;

/**
 * @author ： 手工接入方法
 * @version 1.0
 * @since 2022/5/28 15:32
 */
@Service
@BanAuto
public class NbOrg {
    /**
     * code:getUserIrInfoFromRedis
     * name:Redis获取用户就职信息
     * desc:undefined
     **/

    @Resource
    private RedisUtil redisClient;

    @BanAuto
    public AddGetUserIrInfoFromRedisRespDto addGetUserIrInfoFromRedis(AddGetUserIrInfoFromRedisReqDto reqDto) {
        AddGetUserIrInfoFromRedisRespDto retData = new AddGetUserIrInfoFromRedisRespDto();
        String str = (String) redisClient.get("inductionInfo-" + reqDto.getOriginalRoleMemberId());
        if (str == null || str.isEmpty()) {
            return retData;
        }
        UserIndInfoForRedis redisRetData = JSONObject.parseObject(str, UserIndInfoForRedis.class);
        if (redisRetData.getUserIndList() == null) {
            retData.setOrgInductionRecordList(new ArrayList<>());
        } else {
            retData.setOrgInductionRecordList(redisRetData.getUserIndList().stream().map(org -> {
                OrgInductionRecordDto retElm = new OrgInductionRecordDto();
                BeanUtil.copyProperties(org, retElm);
                return retElm;
            }).collect(Collectors.toList()));
        }
        return retData;
    }
    //手工接入方法
}
